// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-11-17

#ifndef __SVR_USERSOCK_H_COMMON_SVR_BASE__
#define __SVR_USERSOCK_H_COMMON_SVR_BASE__

#pragma once

#include "net_socket.h"
#include "base_buffer.h"
#include <common\netmsg\netmsg.h>

namespace JoyServer
{

class CJoyUser;

class CJoyUserSocket : public CJoySocket
{
protected:
    virtual void OnError(int err);
    virtual void OnRecv(CJoyTransmitData* recvData, const sockaddr_in& fromAddr);
public:
    CJoyBuffer  m_partBuf;
public:
    CJoyUserSocket();
    virtual ~CJoyUserSocket();

    using CJoySocket::Send;
    virtual bool Send(CJoyTransmitData* sendData, int& err);
    void SendMsg(const JoyMessage::MessageBase* pMsg);

    CJoyUser* GetUser();
};

class CJoyNetMsgHandler
{
public:
#   define JOY_MSG_CLIENT_DEF(name) virtual void OnNetMsg_##name(const JoyMessage::MC_##name*) {}
#   include <common\netmsg\mc_def.h>

    template<typename MsgType>
    void NetMsg_Dispatch(const MsgType* msg, void (CJoyNetMsgHandler::*pHandler)(const MsgType*));

    virtual void NetMsg_BadData(const JoyMessage::MessageBase* msg){msg;}
    virtual void NetMsg_Recv(const JoyMessage::MessageBase* msg);
};

} // namespace JoyServer

#endif  // __SVR_USERSOCK_H_COMMON_SVR_BASE__